<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  

  <script>
    function sum(a,b) {
      return a + b;
    }

    function validatorfunc(func, ...types) {
  const proxy = new Proxy(func, {
    apply(target, thisArg, argumentsList) {
      types.forEach((t, i) => {
        const arg = argumentsList[i];
        if (typeof arg !== t) {
          throw `第 ${i + 1} 个参数错误`;
        }
      });
       Reflect.apply(target, thisArg, argumentsList);
    },
  });
  return proxy;
}

const sumProxy = validatorfunc(sum, "number", "number");
console.log(sumProxy(1, '3'));
setTimeout(() => {
  console.log(sumProxy(3, 4));
}, 1000);
    
  </script>
</body>
</html>